package com.frcdi.qms.web.controller.equipment;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.equipment.domain.EquipmentTip;
import com.frcdi.qms.equipment.service.IEquipmentTipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备使用前提示信息Controller
 *
 * @author cell
 * @date 2023-10-10
 */
@Api(tags = "设备使用前提示信息")
@RestController
@RequestMapping("/equipment/tip")
public class EquipmentTipController extends BaseController
{
    @Autowired
    private IEquipmentTipService equipmentTipService;

    /**
     * 查询设备使用前提示信息列表
     */
    @ApiOperation("查询设备使用前提示信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentTip equipmentTip)
    {
        startPage();
        List<EquipmentTip> list = equipmentTipService.selectEquipmentTipList(equipmentTip);
        return getDataTable(list);
    }

    /**
     * 导出设备使用前提示信息列表
     */
    @ApiOperation("导出设备使用前提示信息列表")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentTip equipmentTip)
    {
        List<EquipmentTip> list = equipmentTipService.selectEquipmentTipList(equipmentTip);
        ExcelUtil<EquipmentTip> util = new ExcelUtil<EquipmentTip>(EquipmentTip.class);
        util.exportExcel(response, list, "设备使用前提示信息数据");
    }

    /**
     * 获取设备使用前提示信息详细信息
     */
    @ApiOperation("获取设备使用前提示信息详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
    @GetMapping(value = "/{tipId}")
    public AjaxResult getInfo(@PathVariable("tipId") Long tipId)
    {
        return success(equipmentTipService.selectEquipmentTipByTipId(tipId));
    }

    /**
     * 新增设备使用前提示信息
     */
    @ApiOperation("新增设备使用前提示信息")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentTip equipmentTip)
    {
        equipmentTip.setCreateBy(getUsername());
        return toAjax(equipmentTipService.insertEquipmentTip(equipmentTip));
    }

    /**
     * 修改设备使用前提示信息
     */
    @ApiOperation("修改设备使用前提示信息")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentTip equipmentTip)
    {
        equipmentTip.setUpdateBy(getUsername());
        return toAjax(equipmentTipService.updateEquipmentTip(equipmentTip));
    }

    /**
     * 删除设备使用前提示信息
     */
    @ApiOperation("删除设备使用前提示信息")
    @PreAuthorize("@ss.hasPermi('equipment:type:list')")
	@DeleteMapping("/{tipIds}")
    public AjaxResult remove(@PathVariable Long[] tipIds)
    {
        return toAjax(equipmentTipService.deleteEquipmentTipByTipIds(tipIds));
    }
}
